function init() {
	tinyMCEPopup.resizeToInnerSize();
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function insertWebtreatsLink() {
	
	var tagtext;
	
	var portfolio = document.getElementById('portfolio_panel');
	var style = document.getElementById('style_panel');
	var contact = document.getElementById('contact_panel');
	
	// who is active ?
	if (portfolio.className.indexOf('current') != -1) {
		var catid = document.getElementById('portfolio_category').value;
		
		var column = document.getElementById('portfolio_columns').value;
		
		var max = document.getElementById('portfolio_max').value;
		var showtype = getCheckedValue(document.getElementsByName('showtype'));
		if (catid != 0 )
			tagtext = "[portfolio cat="+ catid + " column="+ column + " link="+ showtype + " max="+ max + "]";
		else
			tinyMCEPopup.close();
	}

	if (style.className.indexOf('current') != -1) {
		var styleid = document.getElementById('style_shortcode').value;
		if (styleid != 0 ){
			tagtext = "["+ styleid + "]Insert your text here[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'twitter' ){
			tagtext = "["+ styleid + " count=\"5\" username=\"twiter_username\"]";
		}
		
		if (styleid != 0 && styleid == 'flickr' ){
			tagtext = "["+ styleid + " id=\"flickr_id\" count=\"9\" display=\"latest\" size=\"square\"]";
		}
		
		if (styleid != 0 && styleid == 'recent_posts' ){
			tagtext = "["+ styleid + " count=\"3\" thumbnail=\"true\"]";
		}
		
		if (styleid != 0 && styleid == 'popular_posts' ){
			tagtext = "["+ styleid + " count=\"3\" thumbnail=\"true\"]";
		}
		
		if (styleid != 0 && styleid == 'recent_comments' ){
			tagtext = "["+ styleid + " number=\"5\"]";
		}
		
		if (styleid != 0 && styleid == 'post_tags' ){
			tagtext = "["+ styleid + " number=\"100\"]";
		}
		
		if (styleid != 0 && styleid == 'contact_info' ){
			tagtext = "["+ styleid + " name=\"your_name\" address=\"your_address\" city=\"your_city\" state=\"your_state\" zip=\"your_zip\" phone=\"your_phone\" email=\"your_email\"]";
		}
		
		if (styleid != 0 && styleid == 'youtube' ){
			tagtext = "["+ styleid + " height=\"344\" width=\"425\"]Insert YouTube Video URL[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'vimeo' ){
			tagtext = "["+ styleid + " height=\"300\" width=\"400\"]Insert Vimeo Video URL[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'galleria' ){
			tagtext = "["+ styleid + " transition=\"fade\" height=\"300\" width=\"600\" autoplay=\"false\"]Insert the full URL path to your images[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'fancy_images' ){
			tagtext = "["+ styleid + " height=\"200\" width=\"188\"]Insert the full URL path to your images[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'minimal_tabs' ){
			tagtext = "["+ styleid + " tab1=\"Tab 1\" tab2=\"Tab 2\" tab3=\"Tab 3\"]<br /><br />[tab]Tab content 1[/tab]<br />[tab]Tab content 2[/tab]<br />[tab]Tab content 3[/tab]<br /><br />[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'framed_tabs' ){
			tagtext = "["+ styleid + " tab1=\"Tab 1\" tab2=\"Tab 2\" tab3=\"Tab 3\"]<br /><br />[tab]Tab content 1[/tab]<br />[tab]Tab content 2[/tab]<br />[tab]Tab content 3[/tab]<br /><br />[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'tooltip' ){
			tagtext = "["+ styleid + " width=\"132\" trigger=\"Tooltip Trigger\"]Tooltip Content[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'fancy_table' ){
			tagtext = "["+ styleid + "]<table><br /><tbody><br /><tr><br /><th>Header 1</th><br /><th>Header 2</th><br /><th>Header 3</th><br /><th>Header 4</th><br /><th>Header 5</th><br /></tr><br /><tr><br /><td>Division 1</td><br /><td>Division 2</td><br /><td>Division 3</td><br /><td>Division 4</td><br /><td>Division 5</td><br /></tr><br /></tbody><br /></table><br />[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'button' ){
			tagtext = "["+ styleid + " link=\"#\" target=\"blank\" size=\"small\"]Read More[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'fancy_link' ){
			tagtext = "["+ styleid + " link=\"#\" target=\"blank\"]Read More[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'download_link' ){
			tagtext = "["+ styleid + " link=\"#\"]Read More[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'email_link' ){
			tagtext = "["+ styleid + " email=\"#\"]Read More[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'dropcap1' || styleid == 'dropcap3' ){
			tagtext = "["+ styleid + "]A[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'dropcap2' ){
			tagtext = "["+ styleid + "]A[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'frame_left' || styleid == 'frame_right' || styleid == 'frame_center' ){
			tagtext = "["+ styleid + " alt=\"\" title=\"\"]Insert the full URL path to your image[/" + styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'fancy_titled_box' ){
			tagtext = "["+ styleid + " title=\"Your Title\"]Insert your text here[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'color_box' ){
			tagtext = "["+ styleid + " title=\"Your Title\"]Insert your text here[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'check_list' || styleid == 'arrow_list'|| styleid == 'star_list' ){
			tagtext = "["+ styleid + "]<ul>\r<li>Item #1</li>\r<li>Item #2</li>\r<li>Item #3</li>\r</ul>[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'bullet_list' ){
			tagtext = "["+ styleid + "]<ul>\r<li>Item #1</li>\r<li>Item #2</li>\r<li>Item #3</li>\r</ul>[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'toggle' || styleid == 'toggle_framed'){
			tagtext = "["+ styleid + " title=\"Toggle Title\" variation=\"\"]Insert your text here[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'divider' || styleid == 'divider_top' || styleid == 'clearboth' || styleid == 'divider_padding'){
			tagtext = "["+ styleid + "]";	
		}
		
		if (styleid != 0 && styleid == 'div'){
			tagtext = "["+ styleid + " class=\"\" style=\"\"]<br />Place your content here...<br />[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'span'){
			tagtext = "["+ styleid + " class=\"\" style=\"\"]<br />Place your content here...<br />[/" + styleid + "]";
		}
		
		if (styleid != 0 && styleid == 'one_half_layout'){
			tagtext = "[one_half]<br />Place your content here...<br />[/one_half]<br /><br />[one_half_last]<br />Place your content here...<br />[/one_half_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_third_layout'){
			tagtext = "[one_third]<br />Place your content here...<br />[/one_third]<br /><br />[one_third]<br />Place your content here...<br />[/one_third]<br /><br />[one_third_last]<br />Place your content here...<br />[/one_third_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fourth_layout'){
			tagtext = "[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_fourth_last]<br />Place your content here...<br />[/one_fourth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fifth_layout'){
			tagtext = "[one_fifth]<br />Place your content here...<br />[/one_fifth]<br /><br />[one_fifth]<br />Place your content here...<br />[/one_fifth]<br /><br />[one_fifth]<br />Place your content here...<br />[/one_fifth]<br /><br />[one_fifth]<br />Place your content here...<br />[/one_fifth]<br /><br />[one_fifthh_last]<br />Place your content here...<br />[/one_fifth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_sixth_layout'){
			tagtext = "[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth_last]<br />Place your content here...<br />[/one_sixth_last]<br />";	
		}
		
		
		
		if (styleid != 0 && styleid == 'one_third_two_third'){
			tagtext = "[one_third]<br />Place your content here...<br />[/one_third]<br /><br />[two_third_last]<br />Place your content here...<br />[/two_third_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'two_third_one_third'){
			tagtext = "[two_third]<br />Place your content here...<br />[/two_third]<br /><br />[one_third_last]<br />Place your content here...<br />[/one_third_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fourth_three_fourth'){
			tagtext = "[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[three_fourth_last]<br />Place your content here...<br />[/three_fourth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'three_fourth_one_fourth'){
			tagtext = "[three_fourth]<br />Place your content here...<br />[/three_fourth]<br /><br />[one_fourth_last]<br />Place your content here...<br />[/one_fourth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fourth_one_fourth_one_half'){
			tagtext = "[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_half_last]<br />Place your content here...<br />[/one_half_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fourth_one_half_one_fourth'){
			tagtext = "[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_half]<br />Place your content here...<br />[/one_half]<br /><br />[one_fourth_last]<br />Place your content here...<br />[/one_fourth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_half_one_fourth_one_fourth'){
			tagtext = "[one_half]<br />Place your content here...<br />[/one_half]<br /><br />[one_fourth]<br />Place your content here...<br />[/one_fourth]<br /><br />[one_fourth_last]<br />Place your content here...<br />[/one_fourth_last]<br /><br />";	
		}
		
		if (styleid != 0 && styleid == 'four_fifth_one_fifth'){
			tagtext = "[four_fifth]<br />Place your content here...<br />[/four_fifth]<br /><br />[one_fifth_last]<br />Place your content here...<br />[/one_fifth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_fifth_four_fifth'){
			tagtext = "[one_fifth]<br />Place your content here...<br />[/one_fifth]<br /><br />[four_fifth_last]<br />Place your content here...<br />[/four_fifth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'two_fifth_three_fifth'){
			tagtext = "[two_fifth]<br />Place your content here...<br />[/two_fifth]<br /><br />[three_fifth_last]<br />Place your content here...<br />[/three_fifth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_sixth_five_sixth'){
			tagtext = "[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[five_sixth_last]<br />Place your content here...<br />[/five_sixth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'five_sixth_one_sixth'){
			tagtext = "[five_sixth]<br />Place your content here...<br />[/five_sixth]<br /><br />[one_sixth_last]<br />Place your content here...<br />[/one_sixth_last]<br />";	
		}
		
		if (styleid != 0 && styleid == 'one_sixth_one_sixth_one_sixth_one_half'){
			tagtext = "[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_sixth]<br />Place your content here...<br />[/one_sixth]<br /><br />[one_half_last]<br />Place your content here...<br />[/one_half_last]<br />";	
		}
		

		if ( styleid == 0 ){
			tinyMCEPopup.close();
		}
	}

	if (contact.className.indexOf('current') != -1) {
		var email = document.getElementById('contact_email').value;
		if (email != 0 )
			tagtext = "[contactform email="+ email + "]";
		else
			tinyMCEPopup.close();
		}
	
	if(window.tinyMCE) {
		//TODO: For QTranslate we should use here 'qtrans_textarea_content' instead 'content'
		window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);
		//Peforms a clean up of the current editor HTML. 
		//tinyMCEPopup.editor.execCommand('mceCleanup');
		//Repaints the editor. Sometimes the browser has graphic glitches. 
		tinyMCEPopup.editor.execCommand('mceRepaint');
		tinyMCEPopup.close();
	}
	return;
}
